package com.wlcorp.forcazamis.web.action.baseinfo;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.wlcorp.forcazamis.business.baseinfo.ISampleSourceService;
import com.wlcorp.forcazamis.domain.baseinfo.SampleSource;
import com.wlcorp.forcazamis.domain.system.Staff;
import com.wlcorp.forcazamis.sys.util.ContextUtil;
import com.wlcorp.forcazamis.sys.util.WebUtil;

public class SampleSourceAction extends DispatchAction {
	public ActionForward getSampleSourceList(ActionMapping mapping,ActionForm form,
			HttpServletRequest request,HttpServletResponse response){
		List<SampleSource> sampleSourceList = ContextUtil.getInstance().getSampleSourceService().getSampleSourceList(null);
		request.setAttribute("sampleSourceList",sampleSourceList);
		return mapping.findForward("list");
	}
	
	public ActionForward getSampleSource(ActionMapping mapping,ActionForm form,
			HttpServletRequest request,HttpServletResponse response){
		SampleSource sampleSource = new SampleSource();
		WebUtil.setRequestToObject(request,sampleSource);
		sampleSource = ContextUtil.getInstance().getSampleSourceService().getSampleSourceById(sampleSource.getSourceId());
		if(null == sampleSource){
			sampleSource = new SampleSource();
		}
		request.setAttribute("sampleSource",sampleSource);
		return mapping.findForward("modify");
	}
	
	public ActionForward modifySampleSource(ActionMapping mapping,ActionForm form,
			HttpServletRequest request,HttpServletResponse response){
		SampleSource sampleSource = new SampleSource();
		WebUtil.setRequestToObject(request,sampleSource);
		ContextUtil.getInstance().getSampleSourceService().saveSampleSource(sampleSource);
		List<Staff> staffList = ContextUtil.getInstance().getStaffService().getStaffList(new Staff());
		WebUtil.setAlertMessage(request,"操作成功！");
		request.setAttribute("staffList",staffList);
		request.setAttribute("sampleSource",sampleSource);
		return mapping.findForward("modify");
	}
	public ActionForward deleteSampleSource(ActionMapping mapping,ActionForm form,
			HttpServletRequest request,HttpServletResponse response){
		String sourceId=request.getParameter("sampleSourceId");
		if (null!=sourceId) {
			ISampleSourceService service = ContextUtil.getInstance().getSampleSourceService();
			SampleSource sampleSource = service.getSampleSourceById(Long.parseLong(sourceId));
			if(null!=sampleSource){
				service.deleteSampleSource(sampleSource);
			}
		}
		return getSampleSourceList(mapping,form,request,response);
	}
}
